#include "util.h"
#include <sys/time.h>

namespace mars {

std::string now() {
    struct timeval t;
    struct tm tm;
    char time_str[64];
    gettimeofday(&t, NULL);

    localtime_r(&t.tv_sec, &tm);
    snprintf(time_str, 64, "%04d-%02d-%02d %02d:%02d:%02d.%03d",
            tm.tm_year + 1900,
            tm.tm_mon + 1,
            tm.tm_mday,
            tm.tm_hour,
            tm.tm_min,
            tm.tm_sec,
            t.tv_usec / 1000);

    return std::string(time_str);
}

} // namespace mars
